G = [['A', 'B', '/', 'D'],
     ['E', 'F', '/', 'H'],
     ['I', 'J', '/', '/'],
     ['M', 'N', 'O', 'P']]

V = [[0] * len(G) for i in range(len(G[0]))]
print(V)
fx = [(1, 0), (0, 1), (-1, 0), (0, -1)]

n = len(G)
m = len(G[0])


def dfs(ex, ey):
    if V[ex][ey] == 0:
        print(G[ex][ey], end="")
        V[ex][ey] = 1
    for pair in fx:
        nx, ny = ex + pair[0], ey + pair[1]
        if nx < 0 or nx >= n or ny < 0 or ny >= m or V[nx][ny] == 1 or G[nx][ny] == '/': continue
        dfs(nx, ny)


dfs(0, 0)
